


class SetDefaultStyles(object):
    
    graph_attributes = {'graph_type':'digraph', 'graph_name':'graphName', 'rankdir':'LR'}
    
    
    edge_attributes = {'arrowtail':'none', 'arrowhead':'normal',
     'color':'black', 'fontsize':'10', 'fontname':'Arial'}
    
    general_node = {'style':'filled', 'fontsize':'10', 'fontname':'Arial'}
    species_node = {'color':'orange', 'shape':'ellipse'}
    reaction_node = {'color':'moccasin', 'shape':'rectangle'}
    compartment_node = {}
    
    
    def __init__(self, style_dict):
        if not style_dict:
            style_dict = {}
        self.style_dict = style_dict
        
        self.setGraphStyle()
        self.setEdgeStyle('reactant_edge')
        self.setEdgeStyle('product_edge')
        self.setEdgeStyle('modifier_edge')                
        self.setGeneralNode()
        self.setSpeciesStyle()
        self.setReactionsStyle()
        self.setCompartmentStyle()  

    
    
    def setGraphStyle(self):
        attributes = self.style_dict.get('graph_attributes', {})
        for key, value in self.graph_attributes.items():
            if not attributes.has_key(key):
                attributes[key] = value
        self.style_dict['graph_attributes'] = attributes
    
    def setEdgeStyle(self, edge_type):
        edge = self.style_dict.get(edge_type, {})
        for key, value in self.edge_attributes.items():
            if not edge.has_key(key):
                edge[key] = value
        
        #SBML styles
        #Reversible reactions - arrow head
        if not edge.has_key('reversible'):
            edge['reversible'] = 'normal'
            
        #Fast reactions - what colour
        if not edge.has_key('fast'):
            edge['fast'] = 'red'
         
        self.style_dict[edge_type] = edge   
    
    def setGeneralNode(self):
        attributes = self.style_dict.get('general_node', {})
        for key, value in self.general_node.items():
            if not attributes.has_key(key):
                attributes[key] = value
        self.general_node = attributes    
       
    def setSpeciesStyle(self):
        species_node = self.style_dict.get('species_node', {})
        for key, value in self.general_node.items():
            if not species_node.has_key(key):
                species_node[key] = value
        
        for key, value in self.species_node.items():
            if not species_node.has_key(key):
                species_node[key] = value
                
                
        #SBML styles
        #Boundary condition - Node colour
        #If you don't want a colour, set to False
        if not species_node.has_key('boundaryCondition'):
            species_node['boundaryCondition']  =  "coral"
         
        self.style_dict['species_node'] = species_node
    
    def setReactionsStyle(self):
        node = self.style_dict.get('reaction_node', {})
        for key, value in self.general_node.items():
            if not node.has_key(key):
                node[key] = value
        
        for key, value in self.reaction_node.items():
            if not node.has_key(key):
                node[key] = value
                
        self.style_dict['reaction_node'] = node

    def setCompartmentStyle(self):
        node = self.style_dict.get('compartment_node', {})
        for key, value in self.general_node.items():
            if not node.has_key(key):
                node[key] = value
        
        for key, value in self.compartment_node.items():
            if not node.has_key(key):
                node[key] = value
                 
        self.style_dict['compartment_node'] = node

